import  React,{PropsWithChildren,ReactElement} from "react";
// 提升非react静态方法,将老组件的静态属性提升到新的组件上
import hoistNonReactStatics from 'hoist-non-react-statics';  
let defaultProps = {
    setting:{
        maxLength: 6,
        placeholder: '请输入待办事项'
    }
}
export type DefaultProps = Partial<typeof defaultProps>
//Props是( OwnProps & DefaultProps) 
export const withDefaultInputProps = <Props extends DefaultProps>(OldComponent:React.ComponentType<Props>)=>{ 
    // 在Props中排除掉DefaultProps的属性
    type OwnProps = Omit<Props, keyof DefaultProps> //
    class NewComponent extends React.Component<OwnProps>{
        public render(){
            let props = {...defaultProps,...this.props } as Props
            return <OldComponent {...props}/>
        }
    } 
    return hoistNonReactStatics(NewComponent, OldComponent)
}


// type ComponentType<P = {}> = ComponentClass<P> | FunctionComponent<P>;
